package pta08;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class test3 {

	public static void main(String[] args) throws IOException {

//		//201521123013
//		BufferedReader br = null;
//		try {
//			FileInputStream fis = new FileInputStream("EncodeTest.txt");
//			InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
//			br = new BufferedReader(isr);
//			String line = null;
//			while((line=br.readLine())!=null)
//				System.out.println(line);
//		} finally{
//			if (br!=null){
//				br.close();
//			}
//		}
		
//		BufferedReader input=null;
//		try {
//			input =new BufferedReader(new FileReader("EncodeTest.txt"));
//			String line=null;
//			while((line=input.readLine())!=null){
//				System.out.println(line);
//			}
//		} catch (FileNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}finally {
//			if(input!=null){
//				input.close();
//			}
//		}
		
		BufferedReader input=null;
		String filename="EncodeTest.txt";
		try {
			String dst="EncodeTest1.txt";
			convertGBK2UTF8(filename, dst);
			input =new BufferedReader(new FileReader(dst));
			
			String line=null;
			while((line=input.readLine())!=null){
				System.out.println(line);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}finally {
			if(input!=null){
				input.close();
			}
		}
	}//201521123013
	private static void convertGBK2UTF8(String src, String dst) throws IOException{
		InputStreamReader isr = new InputStreamReader(new FileInputStream(src), "UTF-8");
		OutputStreamWriter osw =new OutputStreamWriter(new FileOutputStream(dst));
		BufferedReader br=new BufferedReader(isr);
		String line=null;
		while((line=br.readLine())!=null){
			osw.write(line+'\n');
		}
		br.close();
		osw.close();
	}
}
